package com.atguigu.daijia.order.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.model.entity.order.OrderMonitor;
import com.atguigu.daijia.model.entity.order.OrderMonitorRecord;
import com.atguigu.daijia.order.service.OrderMonitorService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/monitor")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class OrderMonitorController {

    private final OrderMonitorService orderMonitorService;

    /**
     * 保存订单监控记录到 MongoDB
     * @param orderMonitorRecord
     * @return
     */
    @Operation(summary = "保存订单监控记录到 MongoDB")
    @PostMapping("/saveOrderMonitorRecord")
    public Result<Boolean> saveOrderMonitorRecord(@RequestBody OrderMonitorRecord orderMonitorRecord) {
        Boolean result = orderMonitorService.saveOrderMonitorRecord(orderMonitorRecord);
        return Result.ok(result);
    }

    /**
     * 保存订单监控统计记录
     * @param orderMonitor
     * @return
     */
    @Operation(summary = "保存订单监控统计记录")
    @PostMapping("/saveOrderMonitor")
    public Result<Long> saveOrderMonitor(@RequestBody OrderMonitor orderMonitor) {
        Long result = orderMonitorService.saveOrderMonitor(orderMonitor);
        return Result.ok(result);
    }

    /**
     * 根据订单 ID 查询订单监控统计记录
     * @param orderId
     * @return
     */
    @Operation(summary = "根据订单 ID 查询订单监控统计记录")
    @GetMapping("/getOrderMonitor/{orderId}")
    public Result<OrderMonitor> getOrderMonitorByOrderId(@PathVariable("orderId") Long orderId) {
        OrderMonitor orderMonitor = orderMonitorService.getOrderMonitorByOrderId(orderId);
        return Result.ok(orderMonitor);
    }

    /**
     * 更新订单监控统计记录
     * @param orderMonitor
     * @return
     */
    @Operation(summary = "更新订单监控统计记录")
    @PostMapping("/updateOrderMonitor")
    public Result<Boolean> updateOrderMonitor(@RequestBody OrderMonitor orderMonitor) {
        Boolean result = orderMonitorService.updateOrderMonitor(orderMonitor);
        return Result.ok(result);
    }
}

